package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhVipShare;
import com.laowang.project.system.service.MyCyhVipShareService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

import javax.validation.constraints.NotNull;

/**
 * vip分享Controller
 *
 * @author laowang
 * @date 2023-06-16
 */
@Api(tags = "vip分享接口")
@RestController
@RequestMapping("/vipShare")
public class MyCyhVipShareController extends BaseController {
    @Autowired
    private MyCyhVipShareService myCyhVipShareService;

    /**
     * 导出vip分享列表
     */
    @ApiOperation(value = "小程序端 添加vip分享关系",notes = "")
    @PostMapping("/addOne")
    public AjaxResult addOne(@RequestBody MyCyhVipShare myCyhVipShare) {

        @NotNull(message = "分享的用户不能为空") Integer shareUserId = myCyhVipShare.getShareUserId();
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        if (mid.equals(shareUserId)){
            return AjaxResult.error("自己不能分享给自己");
        }
        myCyhVipShare.setToUserId(mid);
        myCyhVipShareService.insertMyCyhVipShare(myCyhVipShare);

        return AjaxResult.success("操作成功");
    }



    /**
     *
     *
     * 查询vip分享列表
     */
    @ApiOperation(value = "查询vip分享列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipShare:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCyhVipShare myCyhVipShare) {
        startPage();
        List<MyCyhVipShare> list = myCyhVipShareService.selectMyCyhVipShareList(myCyhVipShare);
        return getDataTable(list);
    }

    /**
     * 导出vip分享列表
     */
    @ApiOperation(value = "导出vip分享列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipShare:export')")
    @GetMapping("/export")
    public AjaxResult export(MyCyhVipShare myCyhVipShare) {
        List<MyCyhVipShare> list = myCyhVipShareService.selectMyCyhVipShareList(myCyhVipShare);
        ExcelUtil<MyCyhVipShare> util = new ExcelUtil<MyCyhVipShare>(MyCyhVipShare.class);
        return util.exportExcel(list, "vipShare");
    }

    /**
     * 获取vip分享详细信息
     */
    @ApiOperation(value = "获取vip分享详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipShare:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myCyhVipShareService.selectMyCyhVipShareById(id));
    }

    /**
     * 新增vip分享
     */
    @ApiOperation(value = "新增vip分享",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipShare:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhVipShare myCyhVipShare) {
        return toAjax(myCyhVipShareService.insertMyCyhVipShare(myCyhVipShare));
    }

    /**
     * 修改vip分享
     */
    @ApiOperation(value = "修改vip分享",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipShare:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhVipShare myCyhVipShare) {
        return toAjax(myCyhVipShareService.updateMyCyhVipShare(myCyhVipShare));
    }

    /**
     * 删除vip分享
     */
    @ApiOperation(value = "删除vip分享",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vipShare:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhVipShareService.deleteMyCyhVipShareByIds(ids));
    }
}
